package com.example.design.c.proxy;

/**
 * 静态代理测试类
 */
public class StaticProxyTest {

    public static void main(String[] args) {
        Proxy proxy = new Proxy();
        proxy.Request();
    }
}

//抽象主题
interface Subject{
    void Request();
}

//真实主题
class RealSubject implements Subject{

    @Override
    public void Request() {
        System.out.println("访问真实主题想法！");
    }
}

class Proxy implements Subject{

    private RealSubject realSubject;

    @Override
    public void Request() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        preRequest();
        realSubject.Request();
        postRequest();
    }

    private void preRequest(){
        System.out.println("访问真实主题之前的预处理。");
    }

    private void postRequest(){
        System.out.println("访问真实主题之后的预处理。");
    }
}
